﻿Imports System.Net.Mail

Namespace Website
    Namespace com
        Namespace Mail

            Class MailSender

                'DEFINIR INFORMATIONS CONNEXION SERVEUR MAIL DANS WEB.CONFIG

                Private _destinataire As String
                Private _expediteur As String
                Private _identiteExpediteur As String
                Private _sujet As String
                Private _message As String
                Private _flagMsgSent As Boolean

                Public Sub New(ByVal destinataire As String, ByVal expditeur As String, ByVal identiteExpediteur As String,
                               ByVal sujet As String, ByVal message As String)

                    _destinataire = destinataire
                    _expediteur = expditeur
                    _identiteExpediteur = identiteExpediteur
                    _sujet = sujet
                    _message = message
                    _flagMsgSent = False

                End Sub

                'Méthodes

                Public Sub sendMessage()
                    Try

                        Using mailMessage As New MailMessage()
                            mailMessage.To.Add(_destinataire)
                            mailMessage.Subject = _sujet
                            'Création du message
                            mailMessage.Body = _message

                            Dim smtpClient As New SmtpClient()
                            smtpClient.EnableSsl = True
                            smtpClient.Send(mailMessage)

                            _flagMsgSent = True

                        End Using

                    Catch ex As Exception
                        _flagMsgSent = False
                    End Try
                End Sub

                'Getters / Setters

                Public Property Destinataire() As String
                    Get
                        Return _destinataire
                    End Get
                    Set(ByVal value As String)
                        _destinataire = value
                    End Set
                End Property

                Public Property Expediteur() As String
                    Get
                        Return _expediteur
                    End Get
                    Set(ByVal value As String)
                        _expediteur = value
                    End Set
                End Property

                Public Property IdentiteExpediteur() As String
                    Get
                        Return _identiteExpediteur
                    End Get
                    Set(ByVal value As String)
                        _identiteExpediteur = value
                    End Set
                End Property

                Public Property Sujet() As String
                    Get
                        Return _sujet
                    End Get
                    Set(ByVal value As String)
                        _sujet = value
                    End Set
                End Property

                Public Property Message() As String
                    Get
                        Return _message
                    End Get
                    Set(ByVal value As String)
                        _message = value
                    End Set
                End Property

                Public Property FlagMsgSent() As Boolean
                    Get
                        Return _flagMsgSent
                    End Get
                    Set(ByVal value As Boolean)
                        _flagMsgSent = value
                    End Set
                End Property


            End Class
        End Namespace
    End Namespace
End Namespace